﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Web;

namespace Ryder_US_Website.Utils
{
    /// <summary>
    /// Ryder_US_Website.Utils.UtilHelpers
    /// 
    /// Team Breakers
    /// Author: Đức Minh GIÃ DƯƠNG (Breakers.Terry)
    /// Email: giaduongducminh@gmail.com
    /// </summary>
    public class UtilHelpers
    {

        /// <summary>
        /// Encode a string by MD5 Algorithm.
        /// </summary>
        /// <param name="source">The source string.</param>
        /// <returns>Encoded string</returns>
        public static String MD5Encode(String source)
        {
            String result = "";
            ASCIIEncoding asciiEncoder = new ASCIIEncoding();
            Byte[] byteASCII = asciiEncoder.GetBytes(source);
            MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
            Byte[] byteHashed = md5Hasher.ComputeHash(byteASCII);
            foreach (Byte b in byteHashed)
                result += b.ToString("x2");
            return result;
        }

        /// <summary>
        /// Determines whether the specified TXT is numeric.
        /// </summary>
        /// <param name="txt">The TXT.</param>
        /// <returns>
        ///   <c>true</c> if the specified TXT is numeric; otherwise, <c>false</c>.
        /// </returns>
        public static Boolean IsNumeric(String txt)
        {
            Boolean flag = false;
            Double temp;
            flag = Double.TryParse(txt.Trim(), out temp);
            return flag;
        }

        /// <summary>
        /// Show message.
        /// </summary>
        /// <param name="mess"> The string.</param>
        public static string ShowMessage(string mess)
        {
            string s = "<script type='text/javascript'>";
            s += "alert('" + mess + "');";
            s += "</script>";
            return s;
        }
    }
}
